Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tpu): add tpu queued resources time bound sample. #9617

Merged
merged 29 commits into from
Dec 31, 2024

Conversation

TetyanaYahodska
Copy link
Contributor

@TetyanaYahodska TetyanaYahodska commented Oct 30, 2024

Description

Documentation -> https://cloud.google.com/tpu/docs/queued-resources
This example describes how to create a queuedResource with a specific time-bound configuration. Some configurations are commented out to avoid creating many similar samples.
NodeJs sample -> GoogleCloudPlatform/nodejs-docs-samples#3907

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed Sample Format Guide
  • pom.xml parent set to latest shared-configuration
  • Appropriate changes to README are included in PR
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • Tests pass: mvn clean verify required
  • Lint passes: mvn -P lint checkstyle:check required
  • Static Analysis: mvn -P lint clean compile pmd:cpd-check spotbugs:check advisory only
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@product-auto-label product-auto-label bot added api: tpu Issues related to the Cloud TPU API. samples Issues that are directly related to samples. labels Oct 30, 2024
@TetyanaYahodska TetyanaYahodska added the kokoro:run Add this label to force Kokoro to re-run the tests. label Oct 30, 2024
@TetyanaYahodska TetyanaYahodska marked this pull request as ready for review October 30, 2024 13:04
Copy link

snippet-bot bot commented Oct 30, 2024

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 4, 2024
@TetyanaYahodska TetyanaYahodska added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 4, 2024
@TetyanaYahodska TetyanaYahodska added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 20, 2024
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 26, 2024
@TetyanaYahodska TetyanaYahodska added the kokoro:run Add this label to force Kokoro to re-run the tests. label Dec 19, 2024
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Dec 23, 2024
@TetyanaYahodska TetyanaYahodska added the kokoro:run Add this label to force Kokoro to re-run the tests. label Dec 23, 2024
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Dec 27, 2024
@TetyanaYahodska TetyanaYahodska added the kokoro:run Add this label to force Kokoro to re-run the tests. label Dec 27, 2024
// For more information about supported TPU types for specific zones,
// see https://cloud.google.com/tpu/docs/regions-zones
String zone = "europe-west4-a";
// The name for your TPU.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please match the description with the one in documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Followed documentation for naming and description.

// Software version that specifies the version of the TPU runtime to install.
// For more information see https://cloud.google.com/tpu/docs/runtimes
String tpuSoftwareVersion = "tpu-vm-tf-2.14.1";
// The name for your Queued Resource.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto. Please match the description with the one in documentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out code is not the best practice. It makes a difficult dev experience in docs.
Please remove all the commented imports and code.

If you want to show more than one option, I've suggested a simpler format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Fixed code

tpu/src/main/java/tpu/CreateTimeBoundQueuedResource.java Outdated Show resolved Hide resolved
Comment on lines 151 to 159
// Uncomment this method if you want to use time bound configurations
// Method to convert a string timestamp to a Protobuf Timestamp object
// private static Timestamp convertStringToTimestamp(String timestampString) {
// Instant instant = Instant.parse(timestampString);
// return Timestamp.newBuilder()
// .setSeconds(instant.getEpochSecond())
// .setNanos(instant.getNano())
// .build();
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Removed

tpu/src/main/java/tpu/CreateTimeBoundQueuedResource.java Outdated Show resolved Hide resolved
tpu/src/main/java/tpu/CreateTimeBoundQueuedResource.java Outdated Show resolved Hide resolved
//QueuedResource.QueueingPolicy.newBuilder()
// You can specify a time before which the resource should be allocated.
// corresponds --valid-after-time flag
//.setValidAfterTime(convertStringToTimestamp(validAfterTime))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this line below 106, and modify it to include the validAfterTime directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Fixed

@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Dec 30, 2024
@TetyanaYahodska TetyanaYahodska added the kokoro:run Add this label to force Kokoro to re-run the tests. label Dec 30, 2024
String parent = String.format("projects/%s/locations/%s", projectId, zone);
// Create a Duration object representing 6 hours.
Duration validAfterDuration = Duration.newBuilder().setSeconds(6 * 3600).build();
// Duration validUntilDuration = Duration.newBuilder().setSeconds(6 * 3600).build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend removing this. It can be easily done with a single tweak to this sample.

Comment on lines 68 to 69
// Timestamp validAfterTime = Timestamps.parse("2024-10-14T09:00:00Z");
// Timestamp validUntilTime = Timestamps.parse("2024-12-14T09:00:00Z");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose one of these. Not necessary to show both.

QueuedResource.QueueingPolicy.newBuilder()
// Use one of the following queueing policies
.setValidAfterDuration(validAfterDuration)
// .setValidUntilDuration(validUntilDuration)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this.

Comment on lines 99 to 100
// .setValidAfterTime(validAfterTime)
// .setValidUntilTime(validUntilTime)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose one of these.

Copy link
Contributor

@Sita04 Sita04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly address the comments before merging.

@kokoro-team kokoro-team removed kokoro:run Add this label to force Kokoro to re-run the tests. labels Dec 31, 2024
@TetyanaYahodska TetyanaYahodska added the kokoro:run Add this label to force Kokoro to re-run the tests. label Dec 31, 2024
@TetyanaYahodska TetyanaYahodska merged commit fe97842 into main Dec 31, 2024
10 checks passed
@TetyanaYahodska TetyanaYahodska deleted the tpu_queued_resources_time_bound branch December 31, 2024 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: tpu Issues related to the Cloud TPU API. kokoro:run Add this label to force Kokoro to re-run the tests. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants